<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="en">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">

<script type="text/javascript" src="http://tajs.qq.com/stats?sId=64887707" charset="UTF-8"></script>



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-flash.min.css?v=1.0.2" rel="stylesheet">




  
  
  <link rel="stylesheet" media="all" href="/lib/Han/dist/han.min.css?v=3.3">




<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />


















  
  
    
  
  <link href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.2/dist/jquery.fancybox.min.css" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.lug.ustc.edu.cn/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Photos," />








  <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico?v=5.1.2" />






<meta name="description" content="给博客添加一个相册页面，以展示自己拍摄的一些照片  (≖ᴗ≖)✧">
<meta name="keywords" content="Photos">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo NexT主题内添加相册功能">
<meta property="og:url" content="https://asdfv1929.github.io/2018/05/26/next-add-photos/index.html">
<meta property="og:site_name" content="asdfv1929 &#39;s Home">
<meta property="og:description" content="给博客添加一个相册页面，以展示自己拍摄的一些照片  (≖ᴗ≖)✧">
<meta property="og:locale" content="en">
<meta property="og:updated_time" content="2018-06-21T11:23:46.424Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hexo NexT主题内添加相册功能">
<meta name="twitter:description" content="给博客添加一个相册页面，以展示自己拍摄的一些照片  (≖ᴗ≖)✧">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"hide","offset":12,"offset_float":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://asdfv1929.github.io/2018/05/26/next-add-photos/"/>





  <title>Hexo NexT主题内添加相册功能 | asdfv1929 's Home</title>

  









</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">asdfv1929 's Home</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description"></h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-photos">
          <a href="/photos/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-image"></i> <br />
            
            Photos
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-links">
          <a href="/links/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-address-book"></i> <br />
            
            Links
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            Search
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="Searching..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://asdfv1929.github.io/2018/05/26/next-add-photos/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="asdfv1929">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/headpic.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="asdfv1929 's Home">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">Hexo NexT主题内添加相册功能</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-05-26T20:33:11+08:00">
                2018-05-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/GitBlog/" itemprop="url" rel="index">
                    <span itemprop="name">GitBlog</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/05/26/next-add-photos/" class="leancloud_visitors" data-flag-title="Hexo NexT主题内添加相册功能">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">Visitors&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <p>给博客添加一个相册页面，以展示自己拍摄的一些照片  (≖ᴗ≖)✧<br><a id="more"></a></p>
<h1 id="config-yml"><a href="#config-yml" class="headerlink" title="_config.yml"></a>_config.yml</h1><p>首先新建<code>hexo new page photos</code>相册页面，将会在<code>source/</code>下创建<code>photos/index.md</code>，在其中添加<code>type: photos</code></p>
<p>之后在主题<code>_config.yml</code>文件中对应位置<code>menu</code>里添加<code>Photos: /photos/ || image</code> ，这样生成后就能在页面的对应页面选项中有该相册Tab。</p>
<h1 id="json"><a href="#json" class="headerlink" title="json"></a>json</h1><p>在博客根目录下新建<code>uploadPhotos</code>文件夹，里面将会存放照片以及相关js文件。</p>
<p>新建<code>uploadPhotos/Images/</code>文件夹，然后在其中存放需要在页面中展示的照片集（后续需将该文件夹上传至GitHub相册库，若没有对应库，可新建，并上传图片）。</p>
<p>新建<code>uploadPhotos/tool.js</code>文件，里面内容如下，主要功能是访问照片文件夹，获取每张照片的size和name，并生成对应的json文件：</p>
<p>命令：<code>Git Bash</code>中键入 <code>node tool.js</code>生成json<br>注：若出现<code>Error: Cannot find module &#39;image-size&#39;</code>问题，请在<code>Git Bash</code>中键入对应命令<code>npm install image-size</code>进行安装。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line">&quot;use strict&quot;;</div><div class="line">    const fs = require(&quot;fs&quot;);</div><div class="line">    const sizeOf = require(&apos;image-size&apos;);</div><div class="line">    const path = &quot;Images&quot;;</div><div class="line">    const output = &quot;../themes/next/source/photos/photoslist.json&quot;;</div><div class="line">    var dimensions;</div><div class="line"></div><div class="line">    fs.readdir(path, function (err, files) &#123;</div><div class="line">        if (err) &#123;</div><div class="line">            return;</div><div class="line">        &#125;</div><div class="line">        let arr = [];</div><div class="line">        (function iterator(index) &#123;</div><div class="line">            if (index == files.length) &#123;</div><div class="line">                fs.writeFile(output, JSON.stringify(arr, null, &quot;\t&quot;));</div><div class="line">                return;</div><div class="line">            &#125;</div><div class="line"></div><div class="line">            fs.stat(path + &quot;/&quot; + files[index], function (err, stats) &#123;</div><div class="line">                if (err) &#123;</div><div class="line">                    return;</div><div class="line">                &#125;</div><div class="line">                if (stats.isFile()) &#123;</div><div class="line">                    dimensions = sizeOf(path + &quot;/&quot; + files[index]);</div><div class="line">                    console.log(dimensions.width, dimensions.height);</div><div class="line">                    arr.push(dimensions.width + &apos;.&apos; + dimensions.height + &apos; &apos; + files[index]);</div><div class="line">                &#125;</div><div class="line">                iterator(index + 1);</div><div class="line">            &#125;)</div><div class="line">        &#125;(0));</div><div class="line">    &#125;);</div></pre></td></tr></table></figure></p>
<p>json文件样例如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[</div><div class="line">	&quot;4032.3024 IMG_0391.JPG&quot;,</div><div class="line">	&quot;12500.3874 IMG_0404.JPG&quot;,</div><div class="line">	&quot;4032.3024 IMG_0416.JPG&quot;,</div><div class="line">	&quot;4032.3024 IMG_0424.JPG&quot;,</div><div class="line">	&quot;3024.4032 IMG_0427.JPG&quot;,</div><div class="line">	&quot;4032.3024 IMG_0429.JPG&quot;,</div><div class="line">	&quot;4032.3024 IMG_0430.JPG&quot;</div><div class="line">]</div></pre></td></tr></table></figure></p>
<h1 id="photo-js"><a href="#photo-js" class="headerlink" title="photo.js"></a>photo.js</h1><p>新建<code>themes/next/source/photos/photo.js</code>文件，其中<code>photos</code>文件夹是自己创建的。</p>
<p><code>photos.js</code>内容如下，主要功能是访问json文件内容，遍历每行数据，并在页面对应位置上放置代码，展示图片（其中图片链接为自个GitHub相册库中图片的链接）：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div></pre></td><td class="code"><pre><div class="line">photo =&#123;</div><div class="line">    page: 1,</div><div class="line">    offset: 20,</div><div class="line">    init: function () &#123;</div><div class="line">        var that = this;</div><div class="line">        $.getJSON(&quot;/photos/photoslist.json&quot;, function (data) &#123;</div><div class="line">            that.render(that.page, data);</div><div class="line">            //that.scroll(data);</div><div class="line">        &#125;);</div><div class="line">    &#125;,</div><div class="line"></div><div class="line">    render: function (page, data) &#123;</div><div class="line">        var begin = (page - 1) * this.offset;</div><div class="line">        var end = page * this.offset;</div><div class="line">        if (begin &gt;= data.length) return;</div><div class="line">        var html, imgNameWithPattern, imgName, imageSize, imageX, imageY, li = &quot;&quot;;</div><div class="line">        for (var i = begin; i &lt; end &amp;&amp; i &lt; data.length; i++) &#123;</div><div class="line">           imgNameWithPattern = data[i].split(&apos; &apos;)[1];</div><div class="line">           imgName = imgNameWithPattern.split(&apos;.&apos;)[0]</div><div class="line">           imageSize = data[i].split(&apos; &apos;)[0];</div><div class="line">           imageX = imageSize.split(&apos;.&apos;)[0];</div><div class="line">           imageY = imageSize.split(&apos;.&apos;)[1];</div><div class="line">            li += &apos;&lt;div class=&quot;card&quot; style=&quot;width:330px&quot;&gt;&apos; +</div><div class="line">                    &apos;&lt;div class=&quot;ImageInCard&quot; style=&quot;height:&apos;+ 330 * imageY / imageX + &apos;px&quot;&gt;&apos; +</div><div class="line">                      &apos;&lt;a data-fancybox=&quot;gallery&quot; href=&quot;https://github.com/asdfv1929/BlogPhotos/blob/master/Images/&apos; + imgNameWithPattern + &apos;?raw=true&quot; data-caption=&quot;&apos; + imgName + &apos;&quot;&gt;&apos; +</div><div class="line">                        &apos;&lt;img src=&quot;https://github.com/asdfv1929/BlogPhotos/blob/master/Images/&apos; + imgNameWithPattern + &apos;?raw=true&quot;/&gt;&apos; +</div><div class="line">                      &apos;&lt;/a&gt;&apos; +</div><div class="line">                    &apos;&lt;/div&gt;&apos; +</div><div class="line">                    // &apos;&lt;div class=&quot;TextInCard&quot;&gt;&apos; + imgName + &apos;&lt;/div&gt;&apos; +</div><div class="line">                  &apos;&lt;/div&gt;&apos;</div><div class="line"></div><div class="line">        &#125;</div><div class="line"></div><div class="line">        $(&quot;.ImageGrid&quot;).append(li);</div><div class="line">        $(&quot;.ImageGrid&quot;).lazyload();</div><div class="line">        this.minigrid();</div><div class="line">    &#125;,</div><div class="line"></div><div class="line">    minigrid: function() &#123;</div><div class="line">        var grid = new Minigrid(&#123;</div><div class="line">            container: &apos;.ImageGrid&apos;,</div><div class="line">            item: &apos;.card&apos;,</div><div class="line">            gutter: 12</div><div class="line">        &#125;);</div><div class="line">        grid.mount();</div><div class="line">        $(window).resize(function() &#123;</div><div class="line">           grid.mount();</div><div class="line">        &#125;);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">&#125;</div><div class="line"></div><div class="line">photo.init();</div></pre></td></tr></table></figure></p>
<h1 id="photos-swig"><a href="#photos-swig" class="headerlink" title="photos.swig"></a>photos.swig</h1><p>新建<code>themes/next/layout/photos.swig</code>文件，其内容模仿<code>tag.swig</code>中内容（直接复制粘贴），然后将其中的<code>tag</code>全部替换为<code>photos</code>。</p>
<h1 id="photos-css"><a href="#photos-css" class="headerlink" title="photos.css"></a>photos.css</h1><p>新建<code>themes/next/source/photos/photos.css</code>样式文件，内容如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">.ImageGrid &#123;width: 100%;max-width: 1040px;margin: 0 auto; text-align: center;&#125;</div><div class="line">.card &#123;overflow: hidden;transition: .3s ease-in-out; border-radius: 8px; background-color: #ddd;&#125;</div><div class="line">.ImageInCard &#123;&#125;</div><div class="line">.ImageInCard img &#123;padding: 0 0 0 0;&#125;</div><div class="line">.TextInCard &#123;line-height: 54px; background-color: #ffffff; font-size: 24px;&#125;</div></pre></td></tr></table></figure></p>
<h1 id="page-swig"><a href="#page-swig" class="headerlink" title="page.swig"></a>page.swig</h1><p>修改<code>themes/next/layout/page.swig</code>文件，添加下面代码中中间<code>page.type === &quot;photos&quot;</code>那两行。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line">&#123;% block title %&#125;&#123;#</div><div class="line">#&#125;&#123;% set page_title_suffix = &apos; | &apos; + config.title %&#125;&#123;#</div><div class="line"></div><div class="line">#&#125;&#123;% if page.type === &quot;categories&quot; and not page.title %&#125;&#123;#</div><div class="line">  #&#125;&#123;&#123; __(&apos;title.category&apos;) + page_title_suffix &#125;&#125;&#123;#</div><div class="line">#&#125;&#123;% elif page.type === &quot;tags&quot; and not page.title %&#125;&#123;#</div><div class="line">  #&#125;&#123;&#123; __(&apos;title.tag&apos;) + page_title_suffix &#125;&#125;&#123;#</div><div class="line"></div><div class="line"></div><div class="line">#&#125;&#123;% elif page.type === &quot;photos&quot; and not page.title %&#125;&#123;#</div><div class="line">  #&#125;&#123;&#123; __(&apos;title.photos&apos;) + page_title_suffix &#125;&#125;&#123;#</div><div class="line"></div><div class="line"></div><div class="line">#&#125;&#123;% else %&#125;&#123;#</div><div class="line">  #&#125;&#123;&#123; page.title + page_title_suffix &#125;&#125;&#123;#</div><div class="line">#&#125;&#123;% endif %&#125;&#123;#</div><div class="line">#&#125;&#123;% endblock %&#125;</div></pre></td></tr></table></figure></p>
<p>依旧是该文件中，添加<code>page.type === &quot;photos&quot;</code>那两行：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">&#123;% elif page.type === &apos;categories&apos; %&#125;</div><div class="line">  &lt;div class=&quot;category-all-page&quot;&gt;</div><div class="line">    &lt;div class=&quot;category-all-title&quot;&gt;</div><div class="line">        &#123;&#123; _p(&apos;counter.categories&apos;, site.categories.length) &#125;&#125;</div><div class="line">    &lt;/div&gt;</div><div class="line">    &lt;div class=&quot;category-all&quot;&gt;</div><div class="line">      &#123;&#123; list_categories() &#125;&#125;</div><div class="line">    &lt;/div&gt;</div><div class="line">  &lt;/div&gt;</div><div class="line"></div><div class="line"></div><div class="line">&#123;% elif page.type === &apos;photos&apos; %&#125;</div><div class="line">    &lt;div class=&quot;ImageGrid&quot;&gt;&lt;/div&gt;</div><div class="line"></div><div class="line"></div><div class="line">&#123;% else %&#125;</div><div class="line">  &#123;&#123; page.content &#125;&#125;</div><div class="line">&#123;% endif %&#125;</div></pre></td></tr></table></figure></p>
<h1 id="config-yml-1"><a href="#config-yml-1" class="headerlink" title="_config.yml"></a>_config.yml</h1><p>在主题配置文件<code>_config.yml</code>中相关部分，进行相关的配置（lazyload、fancybox）：<br>首先确保<code>_config.yml</code>中<code>Fancybox</code>部分是否开启：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"># Fancybox</div><div class="line">fancybox: true</div></pre></td></tr></table></figure></p>
<p>之后亦在该文件<code>_config.yml</code>的末尾部分，找到<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">vendors:</div><div class="line">  # Internal path prefix. Please do not edit it.</div><div class="line">  _internal: lib</div></pre></td></tr></table></figure></p>
<p>在这个<code>vendors</code>的选项下面，有对应的<code>fancybox</code>、<code>lazyload</code>配置区域，填写相应的URL即可：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">vendors:</div><div class="line">  # Internal path prefix. Please do not edit it.</div><div class="line">  _internal: lib</div><div class="line"></div><div class="line">  # Internal version: 2.1.3</div><div class="line">  jquery:</div><div class="line"></div><div class="line">  # Internal version: 2.1.5</div><div class="line">  # See: http://fancyapps.com/fancybox/</div><div class="line">  fancybox: https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.min.js</div><div class="line"></div><div class="line">  fancybox_css: https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.min.css</div><div class="line"></div><div class="line">  # Internal version: 1.0.6</div><div class="line">  # See: https://github.com/ftlabs/fastclick</div><div class="line">  fastclick:</div><div class="line"></div><div class="line">  # Internal version: 1.9.7</div><div class="line">  # See: https://github.com/tuupola/jquery_lazyload</div><div class="line">  lazyload: https://cdn.jsdelivr.net/npm/lazyload@2.0.0-beta.2/lazyload.js</div></pre></td></tr></table></figure></p>
<p>之后在<code>_layout.swig</code>中相关信息配置：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">&lt;script type=&quot;text/javascript&quot; src=&quot;https://unpkg.com/minigrid@3.1.1/dist/minigrid.min.js&quot;&gt;&lt;/script&gt;</div><div class="line"></div><div class="line">&lt;link rel=&quot;stylesheet&quot; href=&quot;/photos/photos.css&quot;&gt;</div><div class="line">&lt;script type=&quot;text/javascript&quot; src=&quot;/photos/photo.js&quot;&gt;&lt;/script&gt;</div></pre></td></tr></table></figure></p>
<p>重新生成访问，查看成果。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>以上就是添加相册功能大概流程，因为步骤比较多，且是通过后期回忆步骤进行记录，所以可能存在些许问题，还请原谅，并请把出现的问题在本文下面的评论中点出，我会进行修改。</p>
<p>后续的实现：</p>
<ul>
<li>将照片上传至GitHub相册库时，由于照片分辨率较高，其都达到了两三M以上，上传速度较慢，导致上传进度缓慢。后期想通过代码将照片进行压缩后再上传至相册库。</li>
<li>相册展示整个操作流程为：先上传照片到git库，再生成json文件，之后便是正常的clean、g、d，后期想把压缩、上传照片和生成json文件整合到一起。</li>
<li>目前的照片展示都是所有照片一整块放一起进行瀑布流显示，后期想将照片根据其旅游场景或类别、时间不同进行分类至对应文件夹，并根据类别或时间线显式展示出不同文件夹下的照片。</li>
</ul>
<p>参考链接：<br><a href="https://www.cnblogs.com/xljzlw/p/5137622.html" target="_blank" rel="external">hexo主题中添加相册功能</a><br><a href="https://fchange.github.io/2018/02/18/%E5%A6%82%E4%BD%95%E5%9C%A8Hexo%E4%B8%AD%E5%AE%9E%E7%8E%B0%E7%9B%B8%E5%86%8C%E5%8A%9F%E8%83%BD/" target="_blank" rel="external">如何在Hexo中实现自适应响应式相册功能</a></p>

      
    </div>
    
    
    

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:22px;">------------- 本 文 结 束 <i class="fa fa-paw"></i> 感 谢 您 的 阅 读 -------------</div>
    
</div>

      
    </div>

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>Donate</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.png" alt="asdfv1929 WeChat Pay"/>
        <p>WeChat Pay</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="asdfv1929 Alipay"/>
        <p>Alipay</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>Post author:</strong>
    asdfv1929
  </li>
  <li class="post-copyright-link">
    <strong>Post link:</strong>
    <a href="https://asdfv1929.github.io/2018/05/26/next-add-photos/" title="Hexo NexT主题内添加相册功能">https://asdfv1929.github.io/2018/05/26/next-add-photos/</a>
  </li>
  <li class="post-copyright-license">
    <strong>Copyright Notice: </strong>
    All articles in this blog are licensed under <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> unless stating additionally.
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Photos/" rel="tag"><i class="fa fa-tag"></i> Photos</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/05/26/next-add-music/" rel="next" title="Hexo NexT主题中添加网页音乐播放器功能">
                <i class="fa fa-chevron-left"></i> Hexo NexT主题中添加网页音乐播放器功能
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/06/01/20180601/" rel="prev" title="六一，你懂的">
                六一，你懂的 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="gitalk-container"></div>

    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="/images/headpic.jpg"
              alt="asdfv1929" />
          
            <p class="site-author-name" itemprop="name">asdfv1929</p>
            <p class="site-description motion-element" itemprop="description"></p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives/">
            
                <span class="site-state-item-count">46</span>
                <span class="site-state-item-name">posts</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">14</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">57</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/asdfv1929" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="mailto:asdfv1929@163.com" target="_blank" title="E-Mail">
                  
                    <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://blog.csdn.net/tianlong1929" target="_blank" title="CSDN">
                  
                    <i class="fa fa-fw fa-contao"></i>CSDN</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://music.163.com/#/user/home?id=82875310" target="_blank" title="CloudMusic">
                  
                    <i class="fa fa-fw fa-music"></i>CloudMusic</a>
              </span>
            
          
        </div>


        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://zhengmengping.github.io/" title="Healer" target="_blank">Healer</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.hawky.me/" title="Hawky" target="_blank">Hawky</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chentao.space/" title="Jack Chen" target="_blank">Jack Chen</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://morefox.net/" title="MOREFOX" target="_blank">MOREFOX</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://inspurer.github.io/" title="月小水长" target="_blank">月小水长</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.newt.fun/" title="不羁的脸闪着青涩" target="_blank">不羁的脸闪着青涩</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://stellarkey.github.io/" title="思维之海" target="_blank">思维之海</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://liujunzhou.top/" title="刘俊周" target="_blank">刘俊周</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://anlan.club/" title="Anlance" target="_blank">Anlance</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://iseexuhs.github.io/" title="ISEEX" target="_blank">ISEEX</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://fanlinxi.cn/" title="無曦" target="_blank">無曦</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.pandashen.com/" title="PandaShen" target="_blank">PandaShen</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://blog.fujishiro.cn/" title="FujishiroOtone" target="_blank">FujishiroOtone</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://pengtuo.tech/" title="PeTu" target="_blank">PeTu</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://yizibi.github.io/" title="一之笔" target="_blank">一之笔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.wliwu.com/" title="WeiJiang1996" target="_blank">WeiJiang1996</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.luameows.wang/" title="Lumo's blog" target="_blank">Lumo's blog</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cfzhao.com/" title="ZhaoYuwei's Blog" target="_blank">ZhaoYuwei's Blog</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://error666.github.io/" title="☆＼(￣ー￣)／☆" target="_blank">☆＼(￣ー￣)／☆</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://drew233.github.io/" title="Uncle_drew" target="_blank">Uncle_drew</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://ladies.ren/" title="易山博客" target="_blank">易山博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://yuzhouwan.com/" title="宇宙湾" target="_blank">宇宙湾</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://chenfeiyang.top/" title="Feiyang Chen" target="_blank">Feiyang Chen</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#config-yml"><span class="nav-number">1.</span> <span class="nav-text">_config.yml</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#json"><span class="nav-number">2.</span> <span class="nav-text">json</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#photo-js"><span class="nav-number">3.</span> <span class="nav-text">photo.js</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#photos-swig"><span class="nav-number">4.</span> <span class="nav-text">photos.swig</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#photos-css"><span class="nav-number">5.</span> <span class="nav-text">photos.css</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#page-swig"><span class="nav-number">6.</span> <span class="nav-text">page.swig</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#config-yml-1"><span class="nav-number">7.</span> <span class="nav-text">_config.yml</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#总结"><span class="nav-number">8.</span> <span class="nav-text">总结</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 &mdash; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">asdfv1929</span>

  
</div>

<!-- 
  <div class="powered-by">Powered by <a class="theme-link" href="https://hexo.io">Hexo</a></div>

  <span class="post-meta-divider">|</span>

  <div class="theme-info">Theme &mdash; <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.2</div>

 -->

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  
    <span class="site-uv">
      <i class="fa fa-user"></i> 访问人数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i> 总访问量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>





  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=64887707";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lazyload@2.0.0-beta.2/lazyload.js"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.2/dist/jquery.fancybox.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">

  <script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
   <script type="text/javascript">
        var gitalk = new Gitalk({
          clientID: '5fe36b6fb87ecd8e46f4',
          clientSecret: '075b050ff7b5e6277fe683d300504bfa5e49037c',
          repo: 'asdfv1929.github.io',
          owner: 'asdfv1929',
          admin: ['asdfv1929'],
          id: location.pathname,
          distractionFreeMode: 'true'
        })
        gitalk.render('gitalk-container')
       </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("l2qrG4ju8kp00y3c2cI8tg1y-gzGzoHsz", "LlxAjmFDL6zNzpRAP0cXqfA6");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

</body>
</html>

<!--崩溃欺骗-->
<script type="text/javascript" src="/js/src/titleqipian.js"></script>


<script type="text/javascript" src="https://unpkg.com/minigrid@3.1.1/dist/minigrid.min.js"></script>

<link rel="stylesheet" href="/photos/photos.css">
<script type="text/javascript" src="/photos/photo.js"></script>
